using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using ResourceBlender_Express.Properties;

namespace ResourceBlender_Express {
    /// <summary>
    /// A window for changing application settings
    /// </summary>
    public partial class WinOptions : Window {
        /// <summary>
        /// Initializes a new <see cref="WinOptions"/>.
        /// </summary>
        public WinOptions() {
            InitializeComponent();    
        }
        /// <summary>
        /// Validates user input then returns a DialogResult of true.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        public void btnSave_Click(object sender, RoutedEventArgs e) {
            if(databaseSelector.ValidateSettings()) {
                try {
                    Database db = new Database();
                    db.OpenConnection();
                    db.CloseConnection();
                    Settings.Default.Save();
                    this.DialogResult = true;
                } catch(Exception ex) {
                    MessageBox.Show(this, "Connection failed: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
    }
}
